package client.whiteboard.view;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import client.whiteboard.controller.DisplayController;
import client.whiteboard.controller.GUIController;

import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Hashtable;
public class GUI extends JLayeredPane implements IGui
{
	static final int PEN_MIN = 1;
	static final int PEN_MAX = 9;
	static final int PEN_INIT = 5;
	private JSlider _penSizeSlider;
	private JButton _JSubmitBtn;
	private JButton _JClearBtn;
	public GUI()
	{
		setVisible(true);
		Hashtable penSliderTable = new Hashtable();
		penSliderTable.put(1, new JLabel("1"));
		penSliderTable.put(3, new JLabel("3"));
		penSliderTable.put(5, new JLabel("5"));
		penSliderTable.put(7, new JLabel("7"));
		penSliderTable.put(9, new JLabel("9"));
		_penSizeSlider = new JSlider(JSlider.HORIZONTAL, (int)PEN_MIN, (int)PEN_MAX, (int)PEN_INIT);
		_penSizeSlider.setMajorTickSpacing(2);
		_penSizeSlider.setMinorTickSpacing(1);
		_penSizeSlider.setPaintTicks(true);
		_penSizeSlider.setPaintLabels(true);
		_penSizeSlider.setMinimum(1);
		_penSizeSlider.setFocusable(false);
		_penSizeSlider.setBackground(new Color(255, 255, 255, 0));
		_penSizeSlider.setBounds(15, 470, 150, 45);
		_penSizeSlider.setSize(150, 45);
		_penSizeSlider.setLabelTable(penSliderTable);
		_JSubmitBtn = new JButton("Submit");
		_JClearBtn = new JButton("Clear");
		_JSubmitBtn.setBounds(380, 470, 90, 30);
		_JClearBtn.setBounds(240, 470, 90, 30);
		add(_penSizeSlider);
		add(_JSubmitBtn);
		add(_JClearBtn);
	}
	public void paintComponent(Graphics g)
	{
		
		Graphics2D g2d = (Graphics2D)g;
		g.setColor(new Color(200, 200, 200));
		BasicStroke stroke = new BasicStroke(10, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL, 0);
		g2d.setStroke(stroke);
		g.drawRect(0, 0, 495, 460);
		g.fillRect(0, 460, 500, 70);
		_penSizeSlider.setBackground(new Color(200, 200, 200));
		
		_penSizeSlider.repaint();
		_JSubmitBtn.repaint();
		_JClearBtn.repaint();
	}
	public void update() {
		repaint();
	}
	@Override
	public void setController(DisplayController displayController, GUIController guiController)
	{
		addMouseListener(guiController);
		addMouseMotionListener(guiController);
		_penSizeSlider.addChangeListener(guiController);
		_JSubmitBtn.addActionListener(guiController);
		_JClearBtn.addActionListener(guiController);
		_JClearBtn.addActionListener(displayController);
	}
	public void stateChanged(ChangeEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
